import { reactive } from 'vue';


type  Discount = {
	discount: number
	money: number
}

type Discounts = {
	list:Array<Discount>,
	balance: number
}

export type State = {
	discounts:Discounts
	token:  string 
};

export const  state = reactive({ discounts: {list:[],balance:0} ,token:''} as State);

export const setBalance = (balance:0) =>{
	state.discounts.balance = balance
}
export const setDiscountList = (discounts:Array<Discount>) =>{
	state.discounts.list = discounts
}
export const getToken = ()=>{
	if(state.token) return state.token
	else {
		state.token =  uni.getStorageSync("token")
		if(state.token == undefined ){
			state.token = ""
		}
		return state.token
	}
}

export const setToken = (token:string)=>{
	uni.setStorageSync("token",token)
}